#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main()
{
    putenv("MY_VAL=1234");
    pid_t id = fork();
    if (id == 0)
    {
        printf("before: I am child, pid:%d, ppid:%d\n", getpid(), getppid());
        //sleep(3);
        //execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
        //execlp("ls", "ls", "-a", "-l", NULL);
        //char* const myargv[] = {
        //    "ls",
        //    "-a",
        //    "-l",
        //    NULL
        //};
        //execv("/usr/bin/ls", myargv);
        //execvp("ls", myargv);
        char* const myenv[] = {
            "a=1",
            "b=2",
            "c=3",
            "MY_VAL=1234",
            NULL
        };
        char* const myargv[] = {
            "otherExe",
            "-a",
            "-b",
            "-c",
            NULL
        };
        execve("/home/zzy/test/otherExe", myargv, myenv);
        printf("after: I am child, pid:%d, ppid:%d\n", getpid(), getppid());
        exit(0);
    }
    pid_t ret = waitpid(id, NULL, 0);
    if (ret == id) 
    {
        printf("father wait %d success\n", ret);
    }
    sleep(3);
    
    return 0;
}
